package com.hs.mod_main.fragment

import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.view.View
import androidx.activity.OnBackPressedCallback
import androidx.navigation.NavOptions
import androidx.navigation.Navigation.findNavController
import com.hs.framework.base.BaseDataBindFragment
import com.hs.framework.utils.DateUtils
import com.hs.mod_main.R
import com.hs.mod_main.databinding.MianFragmentHomeBinding
import java.util.Date


/**
 * 主页：
 */
class HomeFragment : BaseDataBindFragment<MianFragmentHomeBinding>() {
    private lateinit var handle: Handler
    private val ACTION_GET_NOW_TIME : Int = 1001


    init {
        handle  = Handler(Looper.getMainLooper()) { msg ->
            when (msg.what) {
                ACTION_GET_NOW_TIME -> {
                    mBinding?.itemLayout?.nowTime?.text = DateUtils.getYYMMDD()
                    mBinding?.itemLayout?.bottomTimeTv?.text = DateUtils.formatDateHHMM(Date())
                    handle.sendEmptyMessageDelayed(ACTION_GET_NOW_TIME,500)
                }
            }
            true
        }
    }

    override fun initView(view: View, savedInstanceState: Bundle?) {
        handle.sendEmptyMessageDelayed(ACTION_GET_NOW_TIME,500)

        val onClickListener = mBinding?.itemLayout?.getRL?.setOnClickListener {
            val navOptions: NavOptions = NavOptions.Builder()
                .setPopUpTo(R.id.homeFragment, true)
                .build()
            findNavController(view).navigate(
                R.id.action_homeFragment_to_settingsFragment,
                null,
                navOptions
            )
        }


    }





    override fun onDestroyView() {
        super.onDestroyView()


        handle.removeCallbacksAndMessages(null)
        mBinding = null


    }

}